Lua/Client/ClientStaticObject/Static Functions/Create
From JC2-MP Documentation
< Lua | Client | ClientStaticObject
| Returns | ClientStaticObject |
|---|---|
| Prototype | ClientStaticObject.Create(table) |
| Description | Spawns a ClientStaticObject using an argument table. |
Contents
Required values
Type
Name
Notes
Vector3
position
Angle
angle
string
model
Path to the model file. See the model viewer for the full list.
Optional values
Type
Name
Default
Notes
string
collision
""
Path to the collision file. See the model viewer for the full list.
boolean
fixed
true
If false, the object will move smoothly and players can be transported while standing on it.
Notes
- If collision isn't provided, or is invalid, the object will have no collision.
- If fixed is false, you must provide a collision argument.
Example
Create a ramp in front of you when the horn button is pressed
Client
pressed = false
objects = {}
function SpawnRamp()
local vehicle = LocalPlayer:GetVehicle()
-- Make sure they're in a vehicleif not IsValid(vehicle) then
returnendlocal angle = vehicle:GetAngle()
local direction = angle * Vector3.Forward
-- Compensate for velocity. It doesn't always spawn instantly.local position = vehicle:GetPosition() + direction * 35
angle = angle * Angle(math.pi * -0.5, 0, 0)
spawnArgs = {}
spawnArgs.position = position
spawnArgs.angle = angle
spawnArgs.model = "17x48.fl/go666-b.lod"
spawnArgs.collision = "17x48.fl/go666_lod1-b_col.pfx"
local object = ClientStaticObject.Create(spawnArgs)
table.insert(objects, object)
endEvents:Subscribe("PreTick", function()
local currentlyPressed = Input:GetValue(Action.SoundHornSiren) > 0
if currentlyPressed then
if pressed == false then
SpawnRamp()
endendpressed = currentlyPressedend)
-- Make sure to clean up everything on module unload.Events:Subscribe("ModuleUnload", function()
for index, object in ipairs(objects) do
object:Remove()
endend)